package search;
//https://leetcode.cn/leetbook/read/illustration-of-algorithm/58iqo5/
//某班级 n 位同学的学号为 0 ~ n-1。点名结果记录于升序数组 records。假定仅有一位同学缺席，请返回他的学号。
public class LCR_173点名 {
    //二分法
    class Solution {
        public int takeAttendance(int[] records) {
            int i = 0, j = records.length - 1;
            while (i <= j){
                int m = (i + j) / 2;
                if(records[m] == m) i = m+1;
                else j = m-1;
            }
            return i;
        }
    }
    //暴力
    class Solution2 {
        public int takeAttendance(int[] records) {
            if(records == null) return -1;
            for(int i = 0; i < records.length; i ++) {
                if(records[i] != i) {
                    return i;
                }
            }
            return records.length;
        }
    }
}
